package winOrDie.graphicsInterface.RT;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import winOrDie.GameEngine.RT.mp.MapBoard;
import winOrDie.GameEngine.RT.mp.WoD_MapBoard_Event;
import winOrDie.Net.Client.WoD_Client_RT;
import winOrDie.Net.Client.WoD_Client_RT_Event;
import winOrDie.Net.Client.WoD_Peer;
import winOrDie.Net.Client.WoD_Peers_List;

public class Shell_RT_Game {

	
	WoD_Peer woDPeer = null;
	WoD_Client_RT woDClientRT = null;
	WoD_Peers_List woDPeersList = null;
	Long TS_Start = 0L;
	long offset = 0L;
	String mapName = null;
	
	private Display display = null;
	private Shell shell = null;
	private Composite_RT_Game compositeRTGame = null;
	private MapBoard mapBoard = null;
	
	
	public Composite_RT_Game getCompositeRTGame() {
		return compositeRTGame;
	}

	
	public Shell_RT_Game(
			WoD_Peer woDPeer,
			WoD_Client_RT woDClientRT,
			WoD_Peers_List woDPeersList,
			Long TS_Start,
			long offset,
			String mapName) {
		super();
		
		this.woDPeer = woDPeer;
		this.woDClientRT = woDClientRT;
		this.woDPeersList = woDPeersList;
		this.TS_Start = TS_Start;
		display = new Display();
		this.offset = offset;
		this.mapName = mapName;
		
		initialice();
	}
	
	public Shell_RT_Game(
			WoD_Peer woDPeer,
			WoD_Client_RT woDClientRT,
			WoD_Peers_List woDPeersList,
			Long TS_Start,
			Display display,
			long offset,
			String mapName) {
		super();
		
		this.woDPeer = woDPeer;
		this.woDClientRT = woDClientRT;
		this.woDPeersList = woDPeersList;
		this.TS_Start = TS_Start;
		this.display = display;
		this.offset = offset;
		this.mapName = mapName;
		initialice();
	}
	
	
	private void initialice(){
		
		shell = new Shell(display,SWT.MIN);
		shell.setLayout(new FillLayout());//Para que tome todo el espacio disponible
		shell.setText("Win Or Die");
		
		//mapBoard = new MapBoard(shell, SWT.NONE, woDPeer, woDClientRT, woDPeersList, TS_Start);
		
		
		compositeRTGame = new Composite_RT_Game(shell, SWT.NONE, woDPeer, woDClientRT, woDPeersList, TS_Start, offset, mapName);
		display.loadFont("rsc/arcade_pizzadude.ttf");
		
		//y todo lo que inicialicemos
	}

	public void execute (){
		shell.pack();
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}

		}
		
	
		/**
		 * Notify Close Event
		 */
		WoD_MapBoard_Event event = new WoD_MapBoard_Event(getCompositeRTGame().get_Map_Board());
		event.setEvent_Type(WoD_MapBoard_Event.Event_Types.CLOSE);
		getCompositeRTGame().get_Map_Board().notify_WoD_MapBoard_Change(event);
		
		
		shell.dispose();
	}
	


}
